package ch12.d1;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.List;

public class FilesTest {
    @Test
    public void testRead() throws Exception {
        //读文件
//        FileInputStream is=new FileInputStream("javakc107.txt");

        Path p=Path.of("javakc107.txt");
//        InputStream is=Files.newInputStream(p); 不需要字节流了

        //读取所有字节
//        byte[] b=is.readAllBytes();

//        byte[] b=Files.readAllBytes(p); // 不需要读取字节数组了

        String s=Files.readString(p);

        List<String> list=Files.readAllLines(p);

    }

    @Test
    public void testWrite() throws IOException {
        Path p=Path.of("javakc107.txt");
        Files.write(p,"hello".getBytes(), StandardOpenOption.APPEND);

        Files.writeString(p,"hello");

//        Files.write(p,list);

    }

    @Test
    public void testCopy() throws IOException {
        Path p=Path.of("javakc108.txt");
        Path p2=Path.of("d:/javakc108.txt");
        Files.move(p,p2);
    }


}
